package com.pipayshop.controller;

import com.pipayshop.domain.StoreCommodityLive;
import com.pipayshop.domain.vo.LivePageVO;
import com.pipayshop.domain.vo.PageDataVO;
import com.pipayshop.service.PhysicalStoreCommodityLiveService;
import com.pipayshop.entity.vo.ResponseVO;
import com.pipayshop.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 实体店住的服务表 前端控制器
 * </p>
 *
 * @author zxb
 * @since 2023-07-29
 */
//这个好像是不要了，因为之前建错了表好像，但是最好不要乱删除
@Api(value = "实体店住的服务接口",tags = "实体店住的服务接口")
@RestController
@RequestMapping("/pipayshopapi/store-commodity-live")
public class PhysicalStoreCommodityLiveController {

    @Resource
    private PhysicalStoreCommodityLiveService shopCommodityLiveService;

    @GetMapping("selectShopCommodityLiveVO/{pages}/{limit}")
    @ApiOperation("查找实体店住的服务列表")
    public ResponseVO selectShopCommodityLiveVO(@PathVariable Integer pages, @PathVariable Integer limit){
        try {
            PageDataVO pageDataVO = shopCommodityLiveService.selectShopCommodityLiveVO(limit, pages);
            return ResponseVO.getSuccessResponseVo(pageDataVO);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("data_acquisition_failed");
        }
    }

    @GetMapping("selectShopLiveVOByCondition")
    @ApiOperation("条件筛选查找实体店住的服务列表")
    public ResponseVO selectShopLiveVOByCondition(LivePageVO livePageVO){
        try {
            PageDataVO pageDataVO = shopCommodityLiveService.selectShopLiveVOByCondition(livePageVO);
            return ResponseVO.getSuccessResponseVo(pageDataVO);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("filter_failed");
        }
    }

    @GetMapping("selectShopLiveById/{commodityId}")
    @ApiOperation("根据服务id查找服务的详情信息")
    public ResponseVO selectShopLiveById(@PathVariable String commodityId){
        try {
            StoreCommodityLive shopCommodityLive = shopCommodityLiveService.selectShopLiveById(commodityId);
            return ResponseVO.getSuccessResponseVo("根据服务id查找服务的详情信息成功");
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("find_service_detail_info_failed");
        }
    }

    @PostMapping("insertShopLive")
    @ApiOperation("发布实体店住的服务")
    public ResponseVO insertShopLive(@RequestBody StoreCommodityLive shopCommodityLive){
        try {
            boolean result = shopCommodityLiveService.insertShopLive(shopCommodityLive);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("发布实体店住的服务成功");
        }catch (BusinessException e) {
            throw new BusinessException(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("publish_failed");
        }
    }

    @PostMapping("updateShopLive")
    @ApiOperation("根据服务id更改服务信息")
    public ResponseVO updateShopLive(@RequestBody StoreCommodityLive shopCommodityLive){
        try {
            boolean result = shopCommodityLiveService.updateShopLive(shopCommodityLive);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("根据服务id更改服务信息成功");
        }catch (BusinessException e) {
            throw new BusinessException(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("update_service_info_failed");
        }
    }

}
